<?php
namespace app\blog\controller;
use app\blog\model\InfoUser as UserModel;
use app\blog\model\BlogClassify as ClassifyModel;
use app\blog\model\Admin as AdminModel;
use think\Controller;
class Me extends Controller
{
    //载入用户博客管理界面
    public function me_blog_admin()
    {
        $data=ClassifyModel::select();
        $this->assign('data',$data);
        return $this->fetch();
    }
    //载入账号设置
    public function me_account()
    {
        return $this->fetch();
    }
    //载入用户个人中心，个人资料界面
    public function me_info()
    {
        $session=session('cj');
        $id=session('id');
        //查询与该用户匹配的一条数据
        $data=AdminModel::where('username','=',$session)->find();
        //查询与该用户匹配用户信息的一条数据
        $list=UserModel::where('id','=',$id)->find();
        $this->assign('data',$data);
        $this->assign('list',$list);
        return $this->fetch();
    }
    //修改个人资料
    public function update_data()
    {
        $id=session('id');
        $pat_name=$_POST['pat_name'];
        $name=$_POST['name'];
        $sex=$_POST['sex']==1?"男":"女";
        $age=$_POST['age'];
        $introduce=$_POST['introduce'];
        $list=UserModel::get($id);
        $list->pat_name = $pat_name;
        $list->name = $name;
        $list->sex = $sex;
        $list -> age = $age;
        $list -> introduce =$introduce;
        if($list ->save()){
            $this->success('修改成功','/blog/me/me_info','','1');
        }

    }
    public function ajax()
    {
        $data =array('id' =>2,'name' => 'jingyan','website' =>'baidu');
        header("application/x-www-form-urlencoded; charset=utf-8");
        echo json_encode($data);
    }

}